package com.greenyoung.pwiki.uaa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.greenyoung.pwiki.uaa.dao.UserDao;
import com.greenyoung.pwiki.uaa.entity.PermissionEntity;
import com.greenyoung.pwiki.uaa.entity.UserEntity;
import com.greenyoung.pwiki.uaa.service.UserService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author Mr.Zhao
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
    @Autowired
    UserDao userDao;

    /**
     * 查询指定用户具有的权限
     *
     * @param userId 用户id
     * @return 权限标识符字符串集合
     */
    @Override
    public Set<String> findPermissionsByUserId(Long userId) {
        Set<PermissionEntity> permissionEntitys = userDao.findPermissionsByUserId(userId);
        Set<String> permissions = new HashSet<>();
        permissionEntitys.stream().forEach(p -> {
            permissions.add(p.getCode());
        });
        return permissions;
    }

}
